package com.xuecheng.media.controller;

import com.xuecheng.api.media.MediaAuditApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping
public class MediaAuditController implements MediaAuditApi {

    @Autowired
    private MediaService mediaService;

    @PostMapping("m/media/list")
    public PageVO queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {


        return mediaService.queryMediaList(params, model, null);
    }

    @PutMapping("m/media/audit")
    public void auditMedia(@RequestBody MediaAuditVO vo) {

        //auditVo-->dto
        MediaDTO mediaDTO = MediaConvert.INSTANCE.auditVO2dto(vo);

        mediaService.auditMedia(mediaDTO);
    }

    @GetMapping("m/media/preview/{mediaId}")
    public Object previewMedia(@PathVariable Long mediaId) {

        return mediaService.previewMedia(mediaId, null);
    }
}
